import { createStore } from "vuex";
import VuexPersist from "vuex-persist";
import data from '../assets/tabs.json'
import list from "../assets/table.json";
import Alist from '../assets/list.json'
const vuexLocal = new VuexPersist({
    storage: window.localStorage,
})
export default createStore({
    state: {
        Alist: Alist,
        editlist:{},
        list:list.list,
        unread: data.unread,
        read: data.read,
        recycle: data.recycle,
        index:0
    },
    mutations: {
        addread(state, index) {
            state.read.push(state.unread[index])
            state.unread.splice(index,1)
        },
        addrecycle(state, index) {
            state.recycle.push(state.read[index])
            state.read.splice(index, 1)
        },
        addunread(state, index) {
            state.read.push(state.recycle[index])
            console.log(state.recycle[index]);
            state.recycle.splice(index, 1)
        },
        allunread(state) {
            for (var i = 0; i < state.recycle.length; i++){
                state.read.push(state.recycle[i])
            }
            state.recycle=[]
        },
        allread(state) {
            for (var i = 0; i < state.unread.length; i++) {
                state.read.push(state.unread[i])
            }
            state.unread = []
        },
        allrecycle(state) {
            for (var i = 0; i < state.read.length; i++) {
                state.recycle.push(state.read[i])
            }
            state.read = []
        },
        del(state) {
            state.recycle=[]
        },
        read_unread(state,index) {
            state.unread.push(state.read[index])
            state.read.splice(index,1)
        },
        allread_UNread(state) {
            for (var i = 0; i < state.read.length; i++) {
                state.unread.push(state.read[i])
            }
            state.read=[]
        },
        obtainlist(state, item) {
            state.editlist = item
            console.log('11111', state.editlist);
            for (var i = 0; i < state.list.length; i++) {
                if (state.list[i]===item) {
                    state.index=i
                }
            }
        },
        modify(state,list) {
            console.log(3333,list);
            console.log(state.index);
            state.list[state.index]=list
        }
    },
    plugins: [vuexLocal.plugin],
})